from PySide6.QtCore import Qt
from PySide6.QtGui import QAction, QKeySequence
from PySide6.QtWidgets import QMenu


def hum_convert(value):
    units = ["B", "KB", "MB", "GB", "TB", "PB"]
    size = 1024.0
    for i in range(len(units)):
        if (value / size) < 1:
            return "%.2f %s" % (value, units[i])
        value = value / size


def add_action(menu: QMenu, text: str, callback, shortCut: QKeySequence = None):
    new_action = QAction(text, menu)
    if shortCut is not None:
        new_action.setShortcut(shortCut)
    menu.addAction(new_action)
    new_action.triggered.connect(callback)


if __name__ == '__main__':
    print(hum_convert(16384))
